package com.by.zhdoctor.huanxin.api.impl;

import com.by.zhdoctor.huanxin.api.IMUserApi;
import com.by.zhdoctor.huanxin.util.HuanXinInfo;
import com.by.zhdoctor.huanxin.util.ResponseHandler;
import com.by.zhdoctor.huanxin.util.TokenUtil;
import io.swagger.client.ApiResponse;
import io.swagger.client.api.UsersApi;
import io.swagger.client.model.NewPassword;
import io.swagger.client.model.RegisterUsers;
import io.swagger.client.model.UserNames;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by succy on 17-9-3.
 */
@Service
public class IMUserApiImpl implements IMUserApi {
    @Autowired
    private ResponseHandler handler;

    private UsersApi api = new UsersApi();


    @Override
    public ApiResponse<?> createIMUserSingle(RegisterUsers payload) {
        return handler.handle(() ->
            api.orgNameAppNameUsersPostWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, payload, TokenUtil.getAccessToken()));
    }

    @Override
    public ApiResponse<?> getUserByUserName(String username) {
        return handler.handle(() ->
            api.orgNameAppNameUsersUsernameGetWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username));
    }

    @Override
    public ApiResponse<?> resetUserPassword(String username, NewPassword newPassword) {
        return handler.handle(() ->
            api.orgNameAppNameUsersUsernamePasswordPutWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, username, newPassword, TokenUtil.getAccessToken()));
    }

    @Override
    public ApiResponse<?> addFriend(String username, String friendName) {
        return handler.handle(() ->
            api.orgNameAppNameUsersOwnerUsernameContactsUsersFriendUsernamePostWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username, friendName));
    }

    @Override
    public ApiResponse<?> removeFriend(String username, String friendName) {
        return handler.handle(() ->
            api.orgNameAppNameUsersOwnerUsernameContactsUsersFriendUsernameDeleteWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username, friendName));
    }

    @Override
    public ApiResponse<?> getFriendList(String username) {
        return handler.handle(() ->
            api.orgNameAppNameUsersOwnerUsernameContactsUsersGetWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username));
    }

    @Override
    public ApiResponse<?> getBlackList(String username) {
        return handler.handle(() ->
            api.orgNameAppNameUsersOwnerUsernameBlocksUsersGetWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username));
    }

    @Override
    public ApiResponse<?> addToBlackList(String username, UserNames userNames) {
        return handler.handle(() ->
            api.orgNameAppNameUsersOwnerUsernameBlocksUsersPostWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username, userNames));
    }

    @Override
    public ApiResponse<?> removeFromBlackList(String username, String blackName) {
        return handler.handle(() ->
            api.orgNameAppNameUsersOwnerUsernameBlocksUsersBlockedUsernameDeleteWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username, blackName));
    }

    @Override
    public ApiResponse<?> getUserStatus(String username) {
        return handler.handle(() ->
            api.orgNameAppNameUsersUsernameStatusGetWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), username));
    }

    @Override
    public ApiResponse<?> getOfflineMsgCount(String userName) {
        return handler.handle(() ->
        api.orgNameAppNameUsersOwnerUsernameOfflineMsgCountGetWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), userName));
    }
}
